-- DarkStone
-- Created by cheny3 Aug/11/2016
-- 暗之石柱

-- 初始化
function initDarkStone(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 打开建筑界面
            self:openBuildingView(nil, 0, buildingInfo["dialog"]);

            -- 音效
            AudioM.playFx("ui_open1");
        end
    end

    local stoneId = self.gridData.stone_id;

    -- 用一张透明的图片来接收点击事件
    local iconName = "default";
    local iconPath = getLevelItemIconPath(iconName);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.icon:setOpacity(0);

    -- 创建石柱模型，初始停在第一帧
    local effectId = 1192;
    local animation = createEffectAnim(effectId);
    animation:gotoFrameAndPause(0);
    self.item.animation = animation;
    self.item:addChild(animation);

    self.item:setPositionY(10);
 end

 -- 关注石柱失效的事件
function onStoneDisable(self)
    -- 播放石柱关闭特效
    playDarkStoneCloseEffect(self);
end